#ifndef ANIMATEDBUTTON_H
#define ANIMATEDBUTTON_H

#include <QObject>
#include <QPushButton>

#include <QPushButton>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QPainter>

class AnimatedButton : public QPushButton {
    Q_OBJECT
    Q_PROPERTY(qreal scaleFactor READ scaleFactor WRITE setScaleFactor)
    Q_PROPERTY(QColor buttonColor READ buttonColor WRITE setButtonColor)
public:
    explicit AnimatedButton(const QString &text, QWidget *parent = nullptr)
        : QPushButton(text, parent), m_scaleFactor(1.0), m_color("#4CAF50")
    {
        // 初始化动画参数
        setupAnimations();
        // setFixedSize(120, 40);
    }

    qreal scaleFactor() const { return m_scaleFactor; }
    QColor buttonColor() const { return m_color; }

protected:
    void paintEvent(QPaintEvent *event) override;

private slots:
    void startAnimation() {
        animationGroup->setDirection(QAbstractAnimation::Forward);
        animationGroup->start();
    }

private:
    void setScaleFactor(qreal factor) {
        m_scaleFactor = factor;
        update();
    }

    void setButtonColor(QColor color) {
        m_color = color;
        update();
    }

    void setupAnimations();

    qreal m_scaleFactor;
    QColor m_color;
    QParallelAnimationGroup *animationGroup;
};

#endif // ANIMATEDBUTTON_H
